<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    /*
    * let和var的区别：
    * 1.作用域不同，var是函数作用域，let是块级作用域
    * 2.var可以先使用，后声明，let必须先声明后使用
    * 3.var可以重复声明变量，let不能重复声明
    * */
    function f1() {
        let name = "张三";
        var sex = "男";
        console.log(name);
        if (1 === 1){
            console.log(name)
            console.log(sex)
            var score = 19;
        }
        console.log(score);//未超出函数作用域，正常
        //console.log(age);//超出let声明的作用域，报错
    }
    f1();

    // console.log(name);
    // let name;

    // let name = "张三";
    // console.log(name)
    // let name = "李四";
    // console.log(name)

    // const name ="张三";
    // name = "李四";



    // const obj = {};
    // console.log(obj)
    // obj.name = "张三";
    // console.log(obj)

    const obj = {
        name: "张三"
    };
    console.log(obj)
    const obj2 = obj;
    obj2.name = "李四";
    console.log(obj)
    console.log(obj2)
</script>
</html>